package field.validate.test.demo

import grails.test.mixin.TestFor
import spock.lang.Specification
import spock.lang.Unroll

/**
 * See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
 */
@TestFor(Person)
class PersonSpec extends Specification {

    def setup() {
    }

    def cleanup() {
    }
    @Unroll('validate on a person with age #personAge should have returned #shouldBeValid')
    void "test age validation"() {
        expect:
        new Person(age: personAge).validate(['age']) == shouldBeValid
        where:
        personAge | shouldBeValid
        -2        | false
        -1        | false
        0         | true
        1         | true
        119       | true
        120       | true
        121       | false
        122       | false
    }

    @Unroll('validate on a person with age #personAge should have returned #shouldBeValid')
    void "test person validation"() {
        expect:
        new Person(age: personAge,firstName: 'hi',lastName: 'hello').validate() == shouldBeValid
        where:
        personAge | shouldBeValid
        -2        | false
        -1        | false
        0         | true
        1         | true
        119       | true
        120       | true
        121       | false
        122       | false
    }
}

